#include "config.hpp"
#include "business/userbusiness.hpp"
#include "business/medicinebusiness.hpp"
#include "business/purchasebusiness.hpp"
#include "business/alertbusiness.hpp"
#include "business/recordbusiness.hpp"
#include "server.hpp"

using namespace pharmacy_server;

const server::bus_type server::get = true;
const server::bus_type server::post = false;

int main()
{
    easylog::info("pharmacy server started");

    server& svr = server::instance(config::instance().server_port());

    svr.bus_resgister({
        { server::post, "/loginUser", UserBusiness::login_user },
        { server::post, "/registerUser", UserBusiness::register_user },
        { server::post, "/deleteUser", UserBusiness::delete_user },
        { server::post, "/updateUser", UserBusiness::update_user },
        { server::post, "/getUser", UserBusiness::get_user },
        { server::post, "/currentUser", UserBusiness::current_user },
        { server::get,  "/logoutUser", UserBusiness::logout_user },
    });
    svr.bus_resgister({
        { server::post, "/addMedicine", MedicineBusiness::add_medicine },
        { server::post, "/editMedicine", MedicineBusiness::edit_medicine },
        { server::post, "/deleteMedicine", MedicineBusiness::delete_medicine },
        { server::post, "/queryMedicineByName", MedicineBusiness::query_medicine_by_name },
        { server::post, "/queryMedicineByCategory", MedicineBusiness::query_medicines_by_category },
        { server::post, "/queryMedicineByKeyword", MedicineBusiness::query_medicines_by_keyword },
        { server::post, "/takeMedicine", MedicineBusiness::take_medicine },
    });
    svr.bus_resgister({
        { server::get, "/checkStockAlerts", AlertBusiness::check_stock_alerts },
        { server::get, "/checkExpiry", AlertBusiness::check_expiry },
    });
    svr.bus_resgister({
        { server::post, "/createPurchaseOrder", PurchaseBusiness::create_purchase_order },
        { server::post, "/queryPurchaseRecords", PurchaseBusiness::query_purchase_records },
        { server::post, "/querySalesRecords", RecordBusiness::query_sales_records },
    });

    svr.start();

    return 0;
}
